package com.sys.service.impl;

import com.sys.bean.Car;
import com.sys.bean.RespBean;
import com.sys.mapper.CarMapper;
import com.sys.service.CarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CarServiceImpl implements CarService {
    @Autowired
    private CarMapper carMapper;
    @Override
    public boolean insert(Car car) {
        //设置默认状态是在库
        car.setCarState(1);
        return carMapper.insert(car) == 1;
    }

    @Override
    public boolean delete(Integer carId) {
        return carMapper.setState(carId, 0)==1;
    }

    @Override
    public boolean update(Car car) {
        if (carMapper.selectByCarId(car.getCarId()) == null){
            RespBean.error("该车辆不存在，无法修改");
        }
        return carMapper.update(car)==1;
    }

    @Override
    public Car selectByCarId(Integer carId) {
        return carMapper.selectByCarId(carId);
    }

    @Override
    public List<Car> selectByOwnerName(String ownerName) {
        List<Car> carList = carMapper.selectByOwnerName(ownerName);
      return carList;
    }

    @Override
    public List<Car> selectAll() {
        return selectAll();
    }


}
